<?php
require_once 'PHPUnit/Framework.php';

require_once(dirname(__FILE__).'/../../../models/medal/UCModMedal.php');
require_once(dirname(__FILE__).'/../../../libraries/UCLibLogger.php');  
/**
@assert (...) == X    assertEquals(X, method(...))
@assert (...) != X    assertNotEquals(X, method(...))
@assert (...) === X    assertSame(X, method(...))
@assert (...) !== X    assertNotSame(X, method(...))
@assert (...) > X    assertGreaterThan(X, method(...))
@assert (...) >= X    assertGreaterThanOrEqual(X, method(...))
@assert (...) < X    assertLessThan(X, method(...))
@assert (...) <= X    assertLessThanOrEqual(X, method(...))
@assert (...) throws X    @expectedException X
*/
class UCModMedalTest extends PHPUnit_Framework_TestCase {

    private $_bmod;
    private $_uid;
	private $_oid;
    
    protected function setUp()
    {
        UCLibLogger::attach(new StdoutLogOb());
		$this->_uid = $this->providerUserid();
        $this->_bmod = new UCModMedal($this->_uid);
    }

    protected function tearDown()
    {
    }
    
    /**
    * @dataProvider providerUserid
    * 
    */
    function test_addMedal()
    {
		$ret = $this->_bmod->addMedal(array('medal_id' => UCConfMedal::MEDAL_SPECIAL_SUPERMAN,'medal_status' => UCConfMedal::MEDAL_USER_STATUS_GET));
		if(false===$ret)
		{
			$this->assertTrue($ret, 'errno['.$this->_bmod->error_no.'],error:'.$this->_bmod->getLastError());
		}
		$this->_oid = $ret;
    }

	function test_getOneMedalByMedalid()
    {
		$ret = $this->_bmod->getOneMedalByMedalid(UCConfMedal::MEDAL_SPECIAL_SUPERMAN);
		if(false===$ret)
		{
			$this->assertTrue($ret, 'errno['.$this->_bmod->error_no.'],error:'.$this->_bmod->getLastError());
		}
	}

	function test_getOneMedalById()
    {
		if(!$this->_oid)
		{
			$ret = $this->_bmod->addMedal(array('medal_id' => UCConfMedal::MEDAL_SPECIAL_SUPERMAN,'medal_status' => UCConfMedal::MEDAL_USER_STATUS_GET));
			if(false===$ret)
			{
				$this->assertTrue($ret, 'errno['.$this->_bmod->error_no.'],error:'.$this->_bmod->getLastError());
			}
			$this->_oid = $ret;
		}

		$ret = $this->_bmod->getOneMedalById($this->_oid);
		if(false===$ret)
		{
			$this->assertTrue($ret, 'errno['.$this->_bmod->error_no.'],error:'.$this->_bmod->getLastError());
		}
	}

	function test_getAllMedal()
    {
		$ret = $this->_bmod->getAllMedal(UCConfMedal::MEDAL_USER_STATUS_GET);
		if(false===$ret)
		{
			$this->assertTrue($ret, 'errno['.$this->_bmod->error_no.'],error:'.$this->_bmod->getLastError());
		}
	}

	function test_updateMedalInfo($uid)
    {
		if(!$this->_oid)
		{
			$ret = $this->_bmod->addMedal(array('medal_id' => UCConfMedal::MEDAL_SPECIAL_SUPERMAN,'medal_status' => UCConfMedal::MEDAL_USER_STATUS_GET));
			if(false===$ret)
			{
				$this->assertTrue($ret, 'errno['.$this->_bmod->error_no.'],error:'.$this->_bmod->getLastError());
			}
			$this->_oid = $ret;
		}
		$ret = $this->_bmod->test_updateMedalInfo($this->_oid,array('medal_status' => UCConfMedal::MEDAL_USER_STATUS_DONEANDHAVE));
		if(false===$ret)
		{
			$this->assertTrue($ret, 'errno['.$this->_bmod->error_no.'],error:'.$this->_bmod->getLastError());
		}
	}                   
    
	function providerUserid($num)
    {
		$ar_user = array(683831455,1244008966,1216006786,5864186);
        return $ar_param[array_rand($ar_user,1)];
    }
}


?>